/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pgentity.services;

import config.PGConfig;
import pgentity.FindEggs;
import pgentity.User;

/**
 *
 * @author Salm
 */
public class FindEggsServices {
    private FindEggsServices() {}
    private static final FindEggsServices inst;
    public static FindEggsServices inst()
    {
        return inst;
    }
    
    static
    {
        inst = new FindEggsServices();
    }
    
    public FindEggs updateAndGet(User user, long now)
    {
        FindEggs findEggs = FindEggs.getFindEggs(user.getUid());
        switch (findEggs.getState())
        {
            case LEVEL_LOCKED:
                break;
            case CHOOSE_EGGS:
                if (now >= findEggs.getEndEmployTime())
                {
                    findEggs.setState(FindEggs.State.LOCKED);
                }
                break;
            case FINDING:
                if (now >= findEggs.getFoundTime())
                {
                    findEggs.setState(FindEggs.State.FOUND);
                }
                break;
            case COOLDOWN:
                if (now >= findEggs.getEndEmployTime())
                {
                    findEggs.setState(FindEggs.State.LOCKED);
                }
                else if (now >= findEggs.getNextFind())
                {
                    findEggs.setState(FindEggs.State.CHOOSE_EGGS);
                }
                break;
        }
        
        findEggs.saveToDB();
        return findEggs;
    }
}
